feat: Added template for MERN JS Socket.io#175
feat: Added template for MERN JS Socket.io#175Farkhanda-Dalal wants to merge 3 commits intoceltrix-os:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new MERN + Socket.io template to enable real-time chat functionality in JavaScript projects. The template includes both client and server code with Socket.io integration for bidirectional communication.
Key Changes
- Added new "MERN + Socket.io" template option with JavaScript-only support
- Implemented
mernSocketioSetupfunction to handle template installation - Updated CLI prompts to include the new stack option and restrict language choice to JavaScript for this template
Reviewed Changes
Copilot reviewed 34 out of 41 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
index.js |
Added "MERN + Socket.io" to stack choices and new conditional language prompts |
utils/project.js |
Added project setup flow for mern-socketio stack |
utils/installer.js |
Implemented mernSocketioSetup function for dependency installation |
utils/templateManager.js |
Formatting changes only (quote style normalization) |
templates/mern-socketio/** |
New template files for server and client with Socket.io integration |
Files not reviewed (4)
- templates/mern-socketio/client/package-lock.json: Language not supported
- templates/mern-socketio/javascript/client/package-lock.json: Language not supported
- templates/mern-socketio/javascript/server/package-lock.json: Language not supported
- templates/mern-socketio/server/package-lock.json: Language not supported
Comments suppressed due to low confidence (7)
templates/mern-socketio/javascript/server/controller/messages.js:1
- The Message model is imported but never used. The controller uses an in-memory array instead of the database model, making this import redundant and potentially confusing.
templates/mern-socketio/javascript/server/models/Message.js:1 - This file uses ES6 import syntax, but the package.json specifies 'type: commonjs', and other files in the server use CommonJS require() syntax. This will cause a runtime error.
templates/mern-socketio/javascript/server/index.js:1 - This comment indicates Mongoose is not needed, but the package.json still includes 'mongoose' as a dependency, and there's a Message model file. Either remove the dependency and model file, or update the comment to clarify the intended state.
templates/mern-socketio/client/src/components/Chat.js:1 - The socket URL is hardcoded differently here compared to socket.js which uses the same URL. This creates duplicated socket connections and inconsistent configuration. Consider importing the socket from socket.js instead.
templates/mern-socketio/client/src/index.js:1 - This file uses the deprecated ReactDOM.render API. React 18 requires using ReactDOM.createRoot() instead. The main.jsx file already has the correct implementation, so this file appears to be redundant.
templates/mern-socketio/client/src/components/Chat.js:1 - The Chat component listens for 'message' events, but the server emits 'newMessage' events (as seen in the controller). This event name mismatch will prevent messages from being received.
templates/mern-socketio/client/public/index.html:1 - This public/index.html file is redundant. Vite projects use index.html in the project root (which already exists), not in the public folder. This file will be ignored by Vite.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,42 @@ | |||
| const Message = require('../models/Message'); | |||
There was a problem hiding this comment.
The Message model is imported but never used. The controller uses an in-memory array instead of the database model, making this import redundant and potentially confusing.
| const Message = require('../models/Message'); |
| @@ -0,0 +1,20 @@ | |||
| import mongoose from 'mongoose'; | |||
There was a problem hiding this comment.
This file uses ES6 import syntax, but the package.json does not specify 'type: module', and other files in the server use CommonJS require() syntax. This will cause a runtime error.
| require('dotenv').config(); | ||
| const express = require('express'); | ||
| const http = require('http'); | ||
| // Mongoose is no longer needed |
There was a problem hiding this comment.
This comment indicates Mongoose is not needed, but the package.json still includes 'mongoose' as a dependency, and there's a Message model file. Either remove the dependency and model file, or update the comment to clarify the intended state.
| // Mongoose is no longer needed | |
| // Mongoose is not used in this file. If not needed elsewhere in the project, remove the 'mongoose' dependency and any related model files. |
|
|
||
| const socket = io('http://localhost:5000'); // Adjust the URL as needed | ||
|
|
There was a problem hiding this comment.
The socket URL is hardcoded differently here compared to socket.js which uses the same URL. This creates duplicated socket connections and inconsistent configuration. Consider importing the socket from socket.js instead.
| const socket = io('http://localhost:5000'); // Adjust the URL as needed | |
| import socket from '../socket'; // Adjust the path as needed |
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import App from './App'; | ||
|
|
||
| ReactDOM.render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| document.getElementById('root') | ||
| ); No newline at end of file |
There was a problem hiding this comment.
This file uses the deprecated ReactDOM.render API. React 18 requires using ReactDOM.createRoot() instead. The main.jsx file already has the correct implementation, so this file appears to be redundant.
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import App from './App'; | |
| ReactDOM.render( | |
| <React.StrictMode> | |
| <App /> | |
| </React.StrictMode>, | |
| document.getElementById('root') | |
| ); |
| socket.on('message', (message) => { | ||
| setMessages((prevMessages) => [...prevMessages, message]); | ||
| }); | ||
|
|
||
| return () => { | ||
| socket.off('message'); |
There was a problem hiding this comment.
The Chat component listens for 'message' events, but the server emits 'newMessage' events (as seen in the controller). This event name mismatch will prevent messages from being received.
| socket.on('message', (message) => { | |
| setMessages((prevMessages) => [...prevMessages, message]); | |
| }); | |
| return () => { | |
| socket.off('message'); | |
| socket.on('newMessage', (message) => { | |
| setMessages((prevMessages) => [...prevMessages, message]); | |
| }); | |
| return () => { | |
| socket.off('newMessage'); |
index.js
Outdated
| { | ||
| name: "projectType", | ||
| type: "list", | ||
| message: "Select a project type:", | ||
| choices: [ | ||
| "MERN", | ||
| "MEAN", | ||
| "MEVN", | ||
| "MERN (Real-Time with Socket.io)", | ||
| "PERN", | ||
| ], | ||
| }, |
There was a problem hiding this comment.
This 'projectType' prompt appears to be unused - it's not referenced elsewhere in the code and doesn't affect the project setup flow. Additionally, it duplicates the stack selection functionality and includes 'PERN' which isn't implemented.
| { | |
| name: "projectType", | |
| type: "list", | |
| message: "Select a project type:", | |
| choices: [ | |
| "MERN", | |
| "MEAN", | |
| "MEVN", | |
| "MERN (Real-Time with Socket.io)", | |
| "PERN", | |
| ], | |
| }, |
| CLIENT_URL=http://localhost:3000 | ||
| MONGO_URI=URL No newline at end of file |
There was a problem hiding this comment.
The MONGO_URI is included in the .env.example, but the server code doesn't establish a database connection and uses in-memory storage. This configuration is misleading and should be removed or the documentation should clarify it's for future use.
| CLIENT_URL=http://localhost:3000 | |
| MONGO_URI=URL | |
| CLIENT_URL=http://localhost:3000 |
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>MERN Socket.io App</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| </body> | ||
| </html> No newline at end of file |
There was a problem hiding this comment.
This public/index.html file is redundant. Vite projects use index.html in the project root (which already exists), not in the public folder. This file will be ignored by Vite.
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>MERN Socket.io App</title> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| </body> | |
| </html> |
|
Hi @Farkhanda-Dalal , May i know why you have implemented this ?. |
3e3d91c to
291e82d
Compare

Description
Add a new MERN template that demonstrates real-time communication using Socket.io for Javascript.
Related Issue
Closes issue #168
Changes:
project.jsandinstaller.jsto copy the template files and install dependencies.Checklist
Proof of Work:
Created Folder using the template:
Frontend Test:
Testing Endpoints on Postman: